package com.lych.server.controller;

import cn.hutool.core.convert.Convert;
import com.lych.model.dto.RecommendUserDto;
import com.lych.model.vo.NearUserVo;
import com.lych.model.vo.PageResult;
import com.lych.model.vo.TodayBest;
import com.lych.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 今日佳人
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询分页推荐好友列表
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto){
        PageResult pr = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    /**
     * 查看佳人信息
     * @param userId 佳人id
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        TodayBest todayBest = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 查询陌生人问题
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String question = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(question);
    }

    /**
     * 回复陌生人问题
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){

        String id = map.get("userId").toString();
        Long userId = Long.valueOf(id);
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-推荐用户列表
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> list = tanhuaService.cards();
        return ResponseEntity.ok(list);
    }

    /**
     * 探花-喜欢
     * @param likeUserId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity idLove(@PathVariable("id") Long likeUserId){
        tanhuaService.idLove(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花-不喜欢
     * @param likeUserId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId) {
        tanhuaService.unlove(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,
                                 @RequestParam(defaultValue = "2000") String distance){
        List<NearUserVo> list = tanhuaService.search(gender,distance);
        return ResponseEntity.ok(list);
    }
}
